package com.koron.common.core.business.workflow.util;

import org.springframework.util.StringUtils;

import java.nio.charset.StandardCharsets;

/**
 * @author mwangli
 */
public class SecretUtil {

    // private static final String RSA_PUBLIC_KEY = SpringUtils.getBean(WorkFlowConfigProperties.class).getRSApublickey();
    private static final String RSA_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKihfalV5Kt1wwKBDalLK6hGZAc3kxz33B36oeOOZMXTVTtPEHBK7eIXMvOwLMbB7IWkU/9ppZuVG8+tJs0BeekCAwEAAQ==";

    public static String getSecret(String appCode) {
        try {
            if (StringUtils.isEmpty(appCode)) {
                throw new RuntimeException("appCode不能为空");
            }
            appCode += "-" + System.currentTimeMillis();
            return RSAUtil.encrypt(RSAUtil.loadPublicKeyByStr(RSA_PUBLIC_KEY), appCode.getBytes(StandardCharsets.UTF_8));
        } catch (Exception e) {
            throw new RuntimeException("密钥获取失败");
        }
    }
}
